<template>
	<view class="container">
		<!-- 搜索框 -->
		<view class="search-section">
			<view class="search-input u-f-ajc">
				<u-search bg-color="#f4f4f4" shape="square" placeholder="请输入您喜欢的商品" @search="search" :show-action="false"
				 :clearabled="true" v-model="keyword"></u-search>
			</view>
		</view>

		<!-- 轮播图 -->
		<view class="swiper-section">
			<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" indicator-active-color="#fff">
				<swiper-item v-for="item in swiper" :key="item.id" @click="getGoods(item.url)">
					<view class="swiper-item">
						<image :src="item.img" mode=""></image>
					</view>
				</swiper-item>
			</swiper>
		</view>
		<view class="detail2">
			<view class="content" @click="jumpNot">
				<image src="../../static/card/icon1.png" mode=""></image>
				<view class="text">签到积分兑换</view>
			</view>
			<view class="content" @click="jump('/pages/commonality/goods')">
				<image src="../../static/card/icon2.png" mode=""></image>
				<view class="text">399礼包</view>
			</view>
			<view class="content" @click="jump('/pages/service/qrcode')">
				<image src="../../static/card/icon3.png" mode=""></image>
				<view class="text">邀请好友</view>
			</view>
			<view class="content" @click="jump('/pages/service/wechat')">
				<image src="../../static/home/wechat.png" mode=""></image>
				<view class="text">关注公众号</view>
			</view>
			<view class="content" @click="makeCall">
				<image src="../../static/card/icon4.png" mode=""></image>
				<view class="text">在线客服</view>
			</view>
		</view>
		<image class="img-pic" src="../../static/home/icon5.png" mode="" @click="jump('/pages/commonality/goods')"></image>
		<view class="good-list u-f-jsb u-f-fw">
			<!-- <view class="good-item" @click="jump(`/pages/category/commodity?id=${item.goods_id}`)" v-for="(item, index) in goodList.slice(0, 6)" -->
			<view class="good-item" @click="jump(`/pages/category/commodity?id=${item.goods_id}`)" v-for="(item, index) in goodList"
			 :key="index">
				<image :src="item.logo" mode=""></image>
				<view class="title u-line-clamp">{{ item.title }}</view>
				<view class="price u-f-ac">
					<view style="font-size: 28upx;">￥</view>
					{{ item.price_market }}
				</view>
			</view>
		</view>
		<!-- 千元团购 -->
		<!-- <view class="group-section" v-for="(item, index) in groudTitle" :key="index">
			<view class="group-header u-f-jsb">
				<view class="title">{{ item.name }}</view>
				<view class="sub-title u-f1">{{ item.description }}</view>
				<image src="/static/img/index_more.png" mode="" @click="jump('/pages/hundred/hundred?cateid=' + item.id + '&type=' + index)"></image>
			</view>
			<view class="group-content u-f-jsb">
				<view class="group-item u-f-jsb u-f-column" v-for="(it, idx) in item.merge_goods" :key="idx" @click="jump('/pages/hundred/commodity?goodsid=' + it.id, it.id)">
					<image :src="it.thumb" mode=""></image>
					<view class="content u-f-jsb">
						<view class="label">拼团价</view>
						<view class="price">￥{{ it.groupsprice }}</view>
					</view>
					<view class="name uni-ellipsis">{{ it.title }}</view>
				</view>
			</view>
		</view> -->

		<!-- 精选商品 -->
		<view class="goods-section">
			<view class="goods-header">精选商品</view>
			<view class="goods-list u-f-jsb u-f-fw">
				<view class="goods-item" @click="jump(`/pages/category/commodity?id=${item.id}`)" v-for="(item, index) in goodsCate.slice(0, 100)"
				 :key="index">
					<image :src="item.logo" mode=""></image>
					<view class="title u-line-clamp">{{ item.title }}</view>
					<view class="price u-f-ac">
						<view style="font-size: 28upx;">￥</view>
						{{ item.price_market }}
						<text>￥{{ item.price_cost }}</text>
					</view>
				</view>
			</view>
		</view>

		<!-- #ifndef APP-PLUS -->
		<tabbar :current-page="0"></tabbar>
		<!-- #endif -->
	</view>
</template>

<script>
	import service from '@/store/service.js';
	export default {
		data() {
			return {
				// 千元购
				status: 0,
				swiper: [],
				groudList: [],
				groudTitle: [],
				goodsCate: [],
				bulletin: [],
				keyword: '',
				goodsList: '',
				goodList: [],
				lists: [],
				notice: [],
				page: 1,
				last_page: 1
			};
		},
		onLoad: function(e) {
			var self = this;
			if (e.icode) {
				self.icode = e.icode;
				uni.setStorageSync('icode', self.icode);
			}
			self.$http.member.info().then(info => {
				self.getSwiper();
				self.getGroupList();
				self.getGoodsCate(1);
				self.getGoodsList();
			});
		},
		onReachBottom() {
			let that = this;
			if (that.page < that.last_page) {
				that.page = that.page + 1;
				that.getGoodsCate(2);
			} else {
				that.$api.msg('没有更多数据了~');
			}
		},
		methods: {
			makeCall() {
				// uni.makePhoneCall({
				// 	phoneNumber: '400-9918-8395'
				// });
			},
			jumpNot() {
				uni.showToast({
					icon: 'none',
					title: '暂未开放'
				});
			},
			getGoodsList() {
				let self = this;
				self.$http.get(service.api.common.goods, {}).then(function(res) {
					let list = res.data;
					self.lists = list;
					self.goodList = list;
				});
			},
			search(value) {
				// console.log(value);
				uni.navigateTo({
					url: '../shoppingCart/searchList?keyword=' + value
				});
			},
			jumpTab(url) {
				uni.switchTab({
					url: url
				});
			},
			getGoods(url) {
				// console.log(url);
				if (url != '') {
					uni.navigateTo({
						// url: `/pages/category/commodity?id=${id}`
						url: url
					});
				}
			},
			jump(url) {
				uni.navigateTo({
					url: url
				});
			},
			getSwiper() {
				var self = this;
				self.$http.get(service.api.main.swiper, {}).then(function(res) {
					// console.log(res);
					var list = res.data;
					self.swiper = list;
				});
			},

			getGroupList() {
				var self = this;
				self.$http.get(service.api.group.groupList, {}).then(function(res) {
					// console.log(res);
					var list = res.data.categroy;
					self.groudTitle = list;
					self.groudTitle.forEach(function(e) {
						// console.log(element,333);
						// console.log(e.merge_goods);
						self.groudList = e.merge_goods;
					});
				});
			},
			getGoodsCate(e) {
				var self = this;
				self.$http
					.post(service.api.category.goodList, {
						page: self.page,
						isrecommand: 1
					})
					.then(function(res) {
						var list = res.data.data;
						self.last_page = res.data.last_page;
						if (e == 1) {
							self.goodsCate = list;
						} else if (e == 2) {
							self.goodsCate = self.goodsCate.concat(list);
						}
					});
			}
		}
	};
</script>

<style lang="scss" scoped>
	.container {
		background-color: $uni-bg-color;

		.search-section {
			width: 100vw;
			padding: 30rpx;

			.search-input {
				width: 690rpx;
				height: 66rpx;
				background-color: #f1f1f1;
				border-radius: 33rpx;

				text {
					margin-left: 10rpx;
					color: $uni-text-color-grey;
				}
			}
		}

		.swiper-section {
			// margin-top: 20upx;
			width: 100vw;
			height: 330rpx;
			padding: 0 20rpx 20rpx;

			swiper {
				height: 330rpx;
			}

			.swiper-item {
				width: 710rpx;
				height: 330rpx;

				image {
					width: 100%;
					height: 100%;
					border-radius: 10upx;
				}
			}
		}

		.menu-section {
			margin: 30rpx 0;
			margin-top: 60upx;

			.menu-item {
				image {
					width: 100rpx;
					height: 100rpx;
				}
			}
		}

		.notice-section {
			padding: 20rpx;

			.notice {
				width: 710rpx;
				height: 66rpx;
				border-radius: 33rpx;

				background-color: #f4f4f4;

				image {
					width: 121rpx;
					height: 32rpx;
					padding-left: 20rpx;
				}

				.line {
					width: 2rpx;
					height: 30rpx;
					background-color: #c3c3c3;
					margin: 0 15rpx;
				}

				.content {
					color: $uni-text-color;
					font-weight: bold;
				}
			}
		}

		.group-section {
			padding: 20rpx;
			border-bottom: 20rpx solid #f3f3f3;
			box-sizing: border-box;
			width: 100%;

			.group-header {
				.title {
					font-size: 32rpx;
					font-weight: bold;
					color: #000;
				}

				.sub-title {
					font-size: 22rpx;
					color: #999;
					margin-left: 20rpx;
				}

				image {
					width: 94rpx;
					height: 26rpx;
				}
			}

			.group-content {
				display: flex;
				overflow: hidden;

				.group-item {
					// width: 225rpx;
					width: 32%;
					margin: 15rpx;

					image {
						width: 224rpx;
						height: 224rpx;
						margin: 20rpx 0 10rpx;
					}

					.content {
						box-sizing: border-box;
						width: 224rpx;
						height: 47rpx;
						display: flex;
						justify-content: space-around;
						background: linear-gradient(90deg, #ffcc99, #e4842e);
						border-radius: 0px 0px 18upx 18upx;

						.label {
							padding: 0 10upx;
							// width: 128rpx;
							height: 42rpx;
							font-size: 20rpx;
							line-height: 42rpx;
							text-align: center;
							// display: flex;
							// justify-content: center;
							// align-items: center;
							transform: scale(0.9);
							background: #f69739;
							border-radius: 18upx;
						}

						.price,
						.label {
							color: #ffffff;
						}

						.price {
							font-size: 24upx;
							font-weight: bold;
						}
					}

					.name {
						width: 224rpx;
						margin-top: 10rpx;
						// text-align: center;
					}
				}

				& :nth-child(1),
				& :nth-child(3) {
					margin-left: 0;
					margin-right: 0;
				}
			}
		}

		.goods-section {
			background-color: #f3f3f3;
			padding: 0 20rpx 150rpx;

			// margin-top: 190upx;
			.goods-header {
				color: #262626;
				font-size: 34rpx;
				font-weight: bold;
				margin-bottom: 20rpx;
			}

			.goods-list {
				margin-bottom: 50rpx;

				.goods-item {
					border-radius: 20upx;
					width: 345rpx;
					background-color: #ffffff;
					margin-bottom: 20rpx;

					image {
						width: 100%;
						height: 330rpx;
						border-radius: 10upx;
					}

					.title {
						padding: 10rpx 30rpx 0;
						font-size: 30rpx;
						color: $uni-text-color;
						font-weight: bold;
						line-height: 1.4;
					}

					.price {
						padding: 14rpx 24rpx;
						font-size: 36rpx;
						font-weight: bold;
						color: #f81149;

						text {
							font-weight: 100;
							font-size: 20rpx;
							color: #999;
							text-decoration: line-through;
							margin-left: 15rpx;
						}
					}
				}
			}
		}
	}

	// 菜单
	.detail2 {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		justify-content: space-between;
		margin: 40upx 18upx 0 12upx;

		.content {
			width: 20%;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			padding-bottom: 18upx;

			image {
				width: 110upx;
				height: 110upx;
			}

			.text {
				color: #000;
				font-weight: bold;
			}
		}

		.num {
			.money {
				font-size: 32upx;
				font-weight: bold;
				color: #f81149;
			}

			.text {
				font-size: 20upx;
				font-weight: 500;
				color: #4d5467;
				transform: scale(0.9);
			}
		}

		.line {
			width: 3upx;
			height: 50upx;
			background: #eeeeee;
		}
	}

	.img-pic {
		width: 92%;
		height: 175upx;
		margin-left: 30upx;
		// margin-top: 20upx;
	}

	.shop {
		width: 33.33%;
		height: 360upx;
		display: flex;
		margin-left: 20upx;

		image {
			width: 240upx;
			height: 240upx;
			margin: 0 auto;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.title {
			display: -webkit-box;
			overflow: hidden;
			-webkit-line-clamp: 1;
			-webkit-box-orient: vertical;
			margin-bottom: 20upx;
		}

		.content {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding-bottom: 20upx;

			.nprice {
				padding: 0rpx 10rpx 0rpx 0;
				font-size: 36rpx;
				font-weight: bold;
				color: #f81149;
			}

			.oprice {
				font-weight: 100;
				font-size: 20rpx;
				color: #999;
				text-decoration: line-through;
				margin-left: 15rpx;
			}

			.btn {
				background-color: #f8124a;
				color: #fff;
				// padding: 10upx;
				text-align: center;
				width: 180upx;
				height: 74upx;
				line-height: 74upx;
				border-radius: 120upx;
				font-size: 30upx;
				font-weight: bold;
			}
		}
	}

	/deep/ .u-content {
		background-color: #f4f4f4 !important;
	}

	.good-list {
		align-items: baseline;
		margin: 20upx 20upx 0;

		.good-item {
			border-radius: 20upx;
			width: 220rpx;
			background-color: #ffffff;
			margin-bottom: 20rpx;

			image {
				width: 100%;
				height: 220rpx;
				border-radius: 10upx;
			}

			.title {
				padding: 10rpx 10rpx 0;
				font-size: 30rpx;
				color: $uni-text-color;
				font-weight: bold;
				line-height: 1.4;
				display: -webkit-box;
				overflow: hidden;
				-webkit-line-clamp: 1;
				-webkit-box-orient: vertical;
			}

			.price {
				padding: 14rpx;
				font-size: 32rpx;
				font-weight: bold;
				color: #f81149;
				display: flex;
				align-items: center;
				justify-content: center;

				text {
					font-weight: 100;
					font-size: 20rpx;
					color: #999;
					margin-left: 15rpx;
				}
			}
		}
	}
</style>
